package com.centling.smartSealForPhone.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.bean.AuditorEquipInfoBean;

import java.util.List;

/**
 *
 * @author Jessie
 * @date 2016/8/26
 */
public class AuditorDeviceAdapter extends RecyclerView.Adapter<AuditorDeviceAdapter.AuditorDeviceViewHolder> {

    private Context context;
    private List<AuditorEquipInfoBean> auditorEquipInfoBeanList;

    public AuditorDeviceAdapter(Context context, List<AuditorEquipInfoBean> auditorEquipInfoBeanList) {
        this.context = context;
        this.auditorEquipInfoBeanList = auditorEquipInfoBeanList;
    }

    @Override
    public AuditorDeviceAdapter.AuditorDeviceViewHolder onCreateViewHolder(ViewGroup parent,
                                                                           int viewType) {
        return new AuditorDeviceViewHolder(
                LayoutInflater.from(context).inflate(R.layout.item_auditor_device, parent, false));
    }

    @Override
    public void onBindViewHolder(AuditorDeviceAdapter.AuditorDeviceViewHolder holder, int position) {
        holder.sn.setText(auditorEquipInfoBeanList.get(position).getAscSn());
        holder.department.setText(auditorEquipInfoBeanList.get(position).getOrgName());
        holder.sealName.setText(auditorEquipInfoBeanList.get(position).getSealName());
        if ("0".equals(auditorEquipInfoBeanList.get(position).getDeleteFlag())) {
            holder.registerStatus.setText("正常");
        } else {
            holder.registerStatus.setText("已解除注册");
        }
    }

    @Override
    public int getItemCount() {
        return auditorEquipInfoBeanList.size();
    }


    class AuditorDeviceViewHolder extends RecyclerView.ViewHolder {
        TextView sn, department, sealName, registerStatus;

        AuditorDeviceViewHolder(View itemView) {
            super(itemView);
            sn = itemView.findViewById(R.id.tv_auditor_device_sn);
            department = itemView.findViewById(R.id.tv_auditor_device_department);
            sealName = itemView.findViewById(R.id.tv_auditor_device_seal_name);
            registerStatus = itemView.findViewById(R.id.tv_auditor_device_register_status);
        }
    }
}
